﻿using AutoMapper;
using B.S.Data.MES.API.Dto.DtoAssignattributes;
using B.S.Domain.Process.AssignattributesOneModel;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.AssignattributesOneApplications
{
    public class ShowAssignattributesOnesssssCommandHorter : IRequestHandler<ShowAssignattributesOnesssssCommand, APIPageing<List<DtoAssignattributesOne>>>
    {
        IMapper mediator;
        IBaseRepository<AssignattributesOne> processmaintenanceReq;

        public ShowAssignattributesOnesssssCommandHorter(IMapper mediator,IBaseRepository<AssignattributesOne> processmaintenanceReq)
        {
            this.mediator = mediator;
            this.processmaintenanceReq = processmaintenanceReq;
        }

        public async Task<APIPageing<List<DtoAssignattributesOne>>> Handle(ShowAssignattributesOnesssssCommand request, CancellationToken cancellationToken)
        {
            var res = new APIPageing<List<DtoAssignattributesOne>>();
            var list = processmaintenanceReq.GetAll().Where(o => o.zt == true);
            if (!string.IsNullOrEmpty(request.AssignattributesOneEncode))
            {
                list = list.Where(x => x.AssignattributesOneEncode.Contains(request.AssignattributesOneEncode));
            }
            if (request.Id != null)
            {
                list = list.Where(x => x.Id == request.Id);
            }
            var sou = mediator.Map<List<DtoAssignattributesOne>>(list);
            res.Data = sou;

            return res;
        }
    }
}
